

import axios from 'axios';
//http://smarthome.avatar-edu.cn/help/index.htmld

let http = axios.create({
 //baseURL: 'http://smarthome.avatar-edu.cn/',
 //baseURL:"http://111.2.23.43:8088/",
 //baseURL:"192.168.1.109:5000/",
 baseURL:"/",
 //baseURL:'localhost:5000/',
  //baseURL:'http://10.10.1.96:5000/',
  withCredentials: true,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
transformRequest: [function (data) {
    let newData = '';
    for (let k in data) {
      if (data.hasOwnProperty(k) === true) {
        newData += encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) + '&';
      }
    }
    return newData;
}]
});

function apiAxios(method, url, params, response) {
  http({
    method: method,
    url: url,
    params
   
  }).then(function (res) {
    response(res.data);
  }).catch(function (err) {
    response(err);
  })
}

export default {
  get: function (url, params, response) {
    return apiAxios('GET', url, params, response)
  },
  post: function (url, params, response) {
    return apiAxios('POST', url, params, response)
  },
  put: function (url, params, response) {
    return apiAxios('PUT', url, params, response)
  },
  delete: function (url, params, response) {
    return apiAxios('DELETE', url, params, response)
  }
}